/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx.servlet;

import cn.webrx.utils.DbUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * <p>Project: javaweb - Reg
 * <p>Powered by webrx On 2022-03-11 09:52:35
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
@WebServlet("/check")
public class Check extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String a = req.getParameter("account");
        String p = req.getParameter("password");
        DbUtil du = new DbUtil();
        String url = "";
        String msg = "";
        if(du.checkLogin(a,p)){
            msg = "登录成功，欢迎："+a;
            url = "index.jsp";
            req.getSession().setAttribute("account",a);
        }else{
            msg = "登录失败";
            url = "login.jsp";
        }
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.println("<!DOCTYPE html>");
        out.println("<html><head>");
        out.println("<meta charset=\"utf-8\">");
        out.println("<title>登录检查</title>");
        out.printf("<meta http-equiv=\"refresh\" content=\"2;url=%s\">",url);
        out.println("</head><body>");
        out.printf("<h3>%s</h3>",msg);
        out.println("</body></html>");
        out.flush();
        out.close();
    }
}
